﻿// -----------------------------------------------------------------------
// <copyright file="SampleTask.cs" company="The Usual Dosage">
// © 2013 by Matthew M. Martin
// </copyright>
// -----------------------------------------------------------------------

namespace Cadence.NET.Examples
{
    using System;
    using System.Threading;
    using Cadence.NET.Attributes;
    using Cadence.NET.BaseClasses;
    using Cadence.NET.Interfaces;

    /// <summary>
    /// An example of a Cadence task implementing task and notification behaviors.
    /// </summary>
    [TaskBehavior(RunConcurrent = false, RunAsynch = false)]
    [NotificationBehavior(
        NotifyOnTaskComplete = true, 
        NotifyOnTaskError = true, 
        NotifyOnTaskStart = true, 
        NotificationMethods = new Cadence.NET.Attributes.NotificationBehavior.NotifyMethod[] 
        {
            Cadence.NET.Attributes.NotificationBehavior.NotifyMethod.Pushover
        })]
    public class SampleTask : Task
    {
        public override void PerformTask(ITaskContext context)
        {
            try
            {
                // Raise the start event
                OnTaskStarted(context);

                // Do some work!
                System.Console.WriteLine();
                System.Console.WriteLine("Task fired.");
                Thread.Sleep(3000);

                // Raise the completed event
                OnTaskCompleted(context);
            }
            catch (Exception exc)
            {
                context.ErrorContext = exc;
                OnTaskError(context);
            }
        }
    }
}
